from keras.datasets import reuters
import numpy as np

(train_data, train_label), (test_data, test_label) = reuters.load_data(num_words=10000)


def vectorise_sequences(sequences, dimension=10000):
    results = np.zeros((len(sequences), dimension))
    for i, sequence in enumerate(sequences):
        results[i, sequence] = 1.
        return results


x_train = vectorise_sequences(train_data)
x_test = vectorise_sequences(test_data)


def to_one_hot(labels, dimension=46):
    results = np.zeros((len(labels), dimension))
    for i, label in enumerate(labels):
        results[i, label] = 1.
        return results


one_hot_train_label = to_one_hot(train_label)
one_hot_test_label = to_one_hot(test_label)

print('x_train:', x_train.shape)
print('one_hot_train_label:', one_hot_train_label.shape)
print('one_hot_test_label:', one_hot_test_label.shape)

